#!/bin/sh /etc/rc.common

USE_PROCD=1
START=25
STOP=85

BIN_PATH="/usr/sbin"
CONF_PATH="/etc/kea"

start_service() {
	mkdir -p /var/run/kea

	config_load "kea"
	config_foreach start_kea "service"
}

start_kea() {
	local cfg="$1"

	config_get_bool disabled "$cfg" disabled 0
	[ "$disabled" = "0" ] || return

	config_get name "$cfg" name "$cfg"

	case "$name" in
		ctrl_agent|dhcp4|dhcp6|dhcp_ddns)
			name="${name/_/-}"
			cmd="${BIN_PATH}/kea-${name}"
			cnf="${CONF_PATH}/kea-${name}.conf"
			;;
		*)
			return 0
	esac

	procd_open_instance "$name"
	procd_set_param command "$cmd" -c "$cnf"
	procd_set_param env KEA_LOCKFILE_DIR=/tmp
	procd_append_param env KEA_PIDFILE_DIR=/tmp
	procd_set_param file "$cnf"
	procd_set_param stderr 1
	procd_set_param stdout 1
	procd_close_instance ctrl_agent
}
